package com.mz.mattress.admin.api.merchant;

import com.mz.mattress.admin.api.resp.BonusSum;
import com.mz.mattress.admin.api.resp.InvestorSum;
import com.mz.mattress.admin.common.Holder;
import com.mz.mattress.admin.service.InvestorService;
import com.mz.mattress.api.common.Constants;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.entity.Investor;
import com.mz.mattress.api.jwt.MerchantJwt;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//销售端
@Slf4j
@RestController
@RequestMapping(Constants.MERCHANT_PATH + "investor")
public class InvestorController {

    @Autowired
    private InvestorService investorService;

    @GetMapping(value = "/get")
    public Result<Investor> get() {
        MerchantJwt userJwt = Holder.MERCHANT_JWT_THREAD_LOCAL.get();
        Integer typeId = userJwt.getTypeId();
        return investorService.getById(typeId);
    }

    @GetMapping(value = "/headSum")
    public Result<InvestorSum> headSum() {
        MerchantJwt userJwt = Holder.MERCHANT_JWT_THREAD_LOCAL.get();
        Integer typeId = userJwt.getTypeId();
        return investorService.headSum(typeId);
    }

    @GetMapping(value = "/investorSum")
    public Result<BonusSum> investorSum(@RequestParam(required = false) Integer days) {
        MerchantJwt userJwt = Holder.MERCHANT_JWT_THREAD_LOCAL.get();
        return investorService.investorSum(userJwt.getTypeId(), userJwt.getMemberMerId(), days);
    }

    @GetMapping(value = "/{id}")
    public Result<Investor> detail(@PathVariable Integer id) {
        return investorService.getById(id);
    }

//    @GetMapping("/merchantPage")
//    public Result<IPage<Merchant>> listPage(InvestorListReq req) {
//
//        MerchantJwt userJwt = Holder.MERCHANT_JWT_THREAD_LOCAL.get();
//        if (!userJwt.getType().equals(Constants.ROLE_SALE)) {
//            return Result.fail("不是销售");
//        }
//
//        return investorService.merchantPage(req);
//    }
//
//    @GetMapping("/investorPage")
//    public Result<IPage<Investor>> investorPage(InvestorListReq req) {
//        MerchantJwt userJwt = Holder.MERCHANT_JWT_THREAD_LOCAL.get();
//        if (!userJwt.getType().equals(Constants.ROLE_SALE)) {
//            return Result.fail("不是销售");
//        }
//
//        return investorService.investorPage(req);
//    }

}
